home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / games / glchess < prev    next >
Text File  |  2009-09-22  |  2KB  |  82 lines

  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # glChess is a 2D/3D chess game for GNOME. This is the startup
  5. # script which imports the relevant modules. Please keep the startup
  6. # script in sync between glChess and gnome-sudoku.
  7. #
  8. # Copyright (c) 2008  You may use and distribute this
  9. # software under the terms of the GNU General Public License, 
  10. # version 2 or later.
  11.  
  12. import sys
  13. import os
  14.  
  15. # Some version of PyGTK require this to be called before importing the gtk module
  16. import pygtk
  17. pygtk.require('2.0')
  18.  
  19. # Ignore any exceptions writing to stdout using print statements
  20. class SafeStdout:
  21.     def __init__(self):
  22.         self.stdout = sys.stdout
  23.     
  24.     def fileno(self):
  25.         return self.stdout.fileno()
  26.  
  27.     def write(self, data):
  28.         try:
  29.             self.stdout.write(data)
  30.         except:
  31.             pass
  32. sys.stdout = SafeStdout()
  33.  
  34. # Setup bugbuddy to report unhandled exceptions.
  35. try: 
  36.     import bugbuddy
  37.     bugbuddy.install('glchess')
  38. except:
  39.     #No bugbuddy support
  40.     pass
  41.  
  42. def report_error():
  43.     import os.path
  44.     import gettext
  45.     from gettext import gettext as _
  46.  
  47.     gettext.bindtextdomain('gnome-games', os.path.join('/usr', 'share', 'locale'))
  48.     gettext.textdomain('gnome-games')
  49.     # Translators: This is the title of the dialog displayed if glChess cannot start
  50.     title = _("Chess incorrectly installed")
  51.     # Translators: This is the contents of the dialog displayed if glChess cannot start
  52.     description = _("""Chess is not able to start because required application files are not installed. If you are currently upgrading your system please wait until the upgrade has completed.""")
  53.  
  54.     try:
  55.         import gtk
  56.     except ImportError:
  57.         print title
  58.         print '-' * len(title)
  59.         print description
  60.     else:
  61.         dialog = gtk.MessageDialog(type = gtk.MESSAGE_ERROR, message_format = title)
  62.         dialog.format_secondary_text(description)
  63.         dialog.add_button(gtk.STOCK_QUIT, gtk.RESPONSE_CLOSE)
  64.         dialog.run()
  65.     sys.exit(0)
  66.  
  67. # Chek if we are installed
  68. root_dir = os.path.dirname(__file__)
  69. if os.path.exists(os.path.join(root_dir, 'Makefile.am')):
  70.     sys.path.insert(0, os.path.abspath(root_dir))
  71.     import lib
  72.     sys.modules['glchess'] = sys.modules['lib']
  73.  
  74. try:
  75.     # Import glChess from pyexecdir or system installation.
  76.     from glchess.glchess import start_game
  77.     start_game()
  78. except ImportError:
  79.     # Import of glChess failed. Show error message.
  80.     report_error()
  81.  
  82.